package com.facebook.drawee.backends.pipeline;

import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.facebook.cache.common.CacheKey;
import com.facebook.common.internal.Objects;
import com.facebook.common.internal.Objects.ToStringHelper;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Supplier;
import com.facebook.common.logging.FLog;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawable.base.DrawableWithCaches;
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.controller.AbstractDraweeController;
import com.facebook.drawee.drawable.OrientedDrawable;
import com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory;
import com.facebook.imagepipeline.cache.MemoryCache;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.image.CloseableStaticBitmap;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.imagepipeline.image.QualityInfo;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;

public class PipelineDraweeController extends AbstractDraweeController<CloseableReference<CloseableImage>, ImageInfo>
{
  private static final Class<?> TAG = PipelineDraweeController.class;
  private static Experiment sExperiment;
  private final AnimatedDrawableFactory mAnimatedDrawableFactory;
  private CacheKey mCacheKey;
  private Supplier<DataSource<CloseableReference<CloseableImage>>> mDataSourceSupplier;

  @Nullable
  private MemoryCache<CacheKey, CloseableImage> mMemoryCache;
  private final Resources mResources;

  public PipelineDraweeController(Resources paramResources, DeferredReleaser paramDeferredReleaser, AnimatedDrawableFactory paramAnimatedDrawableFactory, Executor paramExecutor, MemoryCache<CacheKey, CloseableImage> paramMemoryCache, Supplier<DataSource<CloseableReference<CloseableImage>>> paramSupplier, String paramString, CacheKey paramCacheKey, Object paramObject)
  {
    super(paramDeferredReleaser, paramExecutor, paramString, paramObject);
    this.mResources = paramResources;
    this.mAnimatedDrawableFactory = paramAnimatedDrawableFactory;
    this.mMemoryCache = paramMemoryCache;
    this.mCacheKey = paramCacheKey;
    init(paramSupplier);
  }

  protected static Experiment getExperiment()
  {
    if (sExperiment == null)
      sExperiment = new Experiment();
    return sExperiment;
  }

  private void init(Supplier<DataSource<CloseableReference<CloseableImage>>> paramSupplier)
  {
    this.mDataSourceSupplier = paramSupplier;
  }

  protected Drawable createDrawable(CloseableReference<CloseableImage> paramCloseableReference)
  {
    Preconditions.checkState(CloseableReference.isValid(paramCloseableReference));
    CloseableImage localCloseableImage = (CloseableImage)paramCloseableReference.get();
    if ((localCloseableImage instanceof CloseableStaticBitmap))
    {
      CloseableStaticBitmap localCloseableStaticBitmap = (CloseableStaticBitmap)localCloseableImage;
      BitmapDrawable localBitmapDrawable = new BitmapDrawable(this.mResources, localCloseableStaticBitmap.getUnderlyingBitmap());
      if ((localCloseableStaticBitmap.getRotationAngle() == 0) || (localCloseableStaticBitmap.getRotationAngle() == -1))
        return localBitmapDrawable;
      return new OrientedDrawable(localBitmapDrawable, localCloseableStaticBitmap.getRotationAngle());
    }
    if (this.mAnimatedDrawableFactory != null)
      return this.mAnimatedDrawableFactory.create(localCloseableImage);
    throw new UnsupportedOperationException("Unrecognized image class: " + localCloseableImage);
  }

  protected CloseableReference<CloseableImage> getCachedImage()
  {
    Object localObject;
    if (!getExperiment().mIsFastCheckEnabled)
      localObject = null;
    do
    {
      return localObject;
      if ((this.mMemoryCache == null) || (this.mCacheKey == null))
        return null;
      localObject = this.mMemoryCache.get(this.mCacheKey);
    }
    while ((localObject == null) || (((CloseableImage)((CloseableReference)localObject).get()).getQualityInfo().isOfFullQuality()));
    ((CloseableReference)localObject).close();
    return null;
  }

  protected DataSource<CloseableReference<CloseableImage>> getDataSource()
  {
    if (FLog.isLoggable(2))
      FLog.v(TAG, "controller %x: getDataSource", Integer.valueOf(System.identityHashCode(this)));
    return (DataSource)this.mDataSourceSupplier.get();
  }

  protected int getImageHash(@Nullable CloseableReference<CloseableImage> paramCloseableReference)
  {
    if (paramCloseableReference != null)
      return paramCloseableReference.getValueHash();
    return 0;
  }

  protected ImageInfo getImageInfo(CloseableReference<CloseableImage> paramCloseableReference)
  {
    Preconditions.checkState(CloseableReference.isValid(paramCloseableReference));
    return (ImageInfo)paramCloseableReference.get();
  }

  protected Resources getResources()
  {
    return this.mResources;
  }

  public void initialize(Supplier<DataSource<CloseableReference<CloseableImage>>> paramSupplier, String paramString, CacheKey paramCacheKey, Object paramObject)
  {
    super.initialize(paramString, paramObject);
    init(paramSupplier);
    this.mCacheKey = paramCacheKey;
  }

  protected void releaseDrawable(@Nullable Drawable paramDrawable)
  {
    if ((paramDrawable instanceof DrawableWithCaches))
      ((DrawableWithCaches)paramDrawable).dropCaches();
  }

  protected void releaseImage(@Nullable CloseableReference<CloseableImage> paramCloseableReference)
  {
    CloseableReference.closeSafely(paramCloseableReference);
  }

  public String toString()
  {
    return Objects.toStringHelper(this).add("super", super.toString()).add("dataSourceSupplier", this.mDataSourceSupplier).toString();
  }

  protected static class Experiment
  {
    private boolean mIsFastCheckEnabled;

    public Experiment setFastCheckEnabled(boolean paramBoolean)
    {
      this.mIsFastCheckEnabled = paramBoolean;
      return this;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.drawee.backends.pipeline.PipelineDraweeController
 * JD-Core Version:    0.6.2
 */